home *** CD-ROM | disk | FTP | other *** search
- /*
- File: LinkSpec.cpp
-
- Contains: Implementation for ODLinkSpec class.
-
- Owned by: Craig Carper
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 5/24/96 jpa 1246074: SOM_CATCH --> SOM_TRY..SOM_ENDTRY
-
- To Do:
- In Progress:
-
- */
-
- #define VARIABLE_MACROS
-
- #define ODLinkSpec_Class_Source
- #include <LinkSpec.xih>
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include "StdProps.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include "StdTypes.xh"
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include "Draft.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- #pragma segment ODLinkSpec
-
- //==============================================================================
- // Constants
- //==============================================================================
- const ODULong kLinkSpecVersion = 1; // Second version
-
- // •••• kODSourcePartKey also defined for Drag & Drop ••••
- // •••• These don't belong here ••••
- #define kODProcessLaunchDateKey 'pldt'
- #define kODSourcePartKey 'part'
- #define kODLinkSpecDataKey 'data'
- #define kODLinkSpecDataSizeKey 'size'
- #define kODLinkSpecVersionKey 'vers'
-
- //==============================================================================
- // ODLinkSpec
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::somUninit
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecsomUninit(ODLinkSpec *somSelf)
- {
- /* ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf); */
- ODLinkSpecMethodDebug("ODLinkSpec","somUninit");
-
- parent_somUninit(somSelf);
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::InitLinkSpec
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecInitLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODPart* part,
- ODByteArray* partData)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","InitLinkSpec");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fProcessLaunchDate = 0;
- */
- _fProcessID.lowLongOfPSN = kNoProcess;
- _fProcessID.highLongOfPSN = 0;
-
- somSelf->InitBaseLinkSpec(ev, part, partData);
-
- if ( part )
- {
- ProcessSerialNumber psn;
- ProcessInfoRec myProcessInfo;
-
- psn.lowLongOfPSN = kCurrentProcess;
- psn.highLongOfPSN = 0;
- myProcessInfo.processAppSpec = NULL;
- myProcessInfo.processName = NULL;
- myProcessInfo.processInfoLength = sizeof(myProcessInfo);
-
- OSErr error = GetProcessInformation(&psn, &myProcessInfo);
- ASSERT((error == 0), kODErrAssertionFailed);
-
- _fProcessID = myProcessInfo.processNumber;
- _fProcessLaunchDate = myProcessInfo.processLaunchDate;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::FromThisDraft (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkSpecFromThisDraft(ODLinkSpec *somSelf, Environment *ev)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","FromThisDraft");
-
- SOM_TRY
-
- ProcessSerialNumber myPSN;
- ProcessInfoRec myProcessInfo;
- Boolean isSamePSN;
-
- myPSN.lowLongOfPSN = kCurrentProcess;
- myPSN.highLongOfPSN = 0;
- myProcessInfo.processAppSpec = NULL;
- myProcessInfo.processName = NULL;
- myProcessInfo.processInfoLength = sizeof(myProcessInfo);
- THROW_IF_ERROR(GetProcessInformation(&myPSN, &myProcessInfo));
- THROW_IF_ERROR(SameProcess(&_fProcessID, &myProcessInfo.processNumber, &isSamePSN));
-
- return (isSamePSN && (myProcessInfo.processLaunchDate == _fProcessLaunchDate));
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::GetOriginatingProcessID
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecGetOriginatingProcessID(ODLinkSpec *somSelf, Environment *ev,
- ProcessSerialNumber *psn)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","GetProcessLaunchDate");
-
- ProcessInfoRec info;
-
- info.processAppSpec = NULL;
- info.processName = NULL;
- info.processInfoLength = sizeof(info);
-
- if ( (GetProcessInformation(&_fProcessID, &info) == noErr) &&
- (info.processLaunchDate == _fProcessLaunchDate) )
- {
- *psn = _fProcessID;
- }
- else
- {
- psn->lowLongOfPSN = kNoProcess;
- psn->highLongOfPSN = 0;
- ODSetSOMException(ev, kODErrCannotGetExternalLink);
- }
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::WriteLinkSpec (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecWriteLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODStorageUnit* su)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","WriteLinkSpec");
-
- SOM_TRY
-
- ODVolatile(su);
-
- ODULong version = kLinkSpecVersion;
- ODULong size;
-
- ODSUForceFocus(ev, su, kODNULL, kODLinkSpec);
- size = su->GetSize(ev);
- su->DeleteValue(ev, size);
-
- TRY
- StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &version);
- StorageUnitSetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &_fProcessID);
- StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &_fProcessLaunchDate);
-
- parent_WriteLinkSpec(somSelf, ev, su);
- CATCH_ALL
- su->Remove(ev);
- RERAISE;
- ENDTRY
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::ReadLinkSpec (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecReadLinkSpec(ODLinkSpec *somSelf, Environment *ev,
- ODStorageUnit* su)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","ReadLinkSpec");
-
- SOM_TRY
-
- ODULong version;
- ProcessSerialNumber processID;
- ODULong processLaunchDate;
- ODULong valueSize;
-
- // Pre-focused property must contain a link spec value
- if (!ODSUExistsThenFocus(ev, su, (ODPropertyName) kODNULL, kODLinkSpec))
- THROW(kODErrNoLinkSpecValue);
-
- StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &version);
- if (version != kLinkSpecVersion)
- THROW(kODErrUnknownLinkSpecVersion);
-
- valueSize = StorageUnitGetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &processID);
- if ( valueSize != sizeof(ProcessSerialNumber) )
- THROW(kODErrCorruptLinkSpecValue);
-
- valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &processLaunchDate);
- if ( valueSize != sizeof(ODULong) )
- THROW(kODErrCorruptLinkSpecValue);
-
- parent_ReadLinkSpec(somSelf, ev, su);
-
- _fProcessID = processID;
- _fProcessLaunchDate = processLaunchDate;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::WriteToAppleEvent
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecWriteToAppleEvent(ODLinkSpec *somSelf, Environment *ev,
- AppleEvent* theAppleEvent)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","WriteToAppleEvent");
-
- SOM_TRY
-
- OSErr error;
- ODPart* part = somSelf->GetPart(ev);
- ODByteArray partData = somSelf->GetPartData(ev);
-
- ODULong version = kLinkSpecVersion;
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecVersionKey, typeLongInteger,
- &version, sizeof(version));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber,
- &_fProcessID, sizeof(_fProcessID));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger,
- &_fProcessLaunchDate, sizeof(_fProcessLaunchDate));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger,
- &part, sizeof(part));
-
- if ( error == noErr )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger,
- &partData._length, sizeof(ODULong));
-
- if ( (error == noErr) && (partData._length > 0) )
- error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar /* ••• need better type here •••• */,
- partData._buffer, partData._length);
-
- DisposeByteArrayStruct(partData);
-
- THROW_IF_ERROR(error);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLinkSpec::ReadFromAppleEvent
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSpecReadFromAppleEvent(ODLinkSpec *somSelf, Environment *ev,
- AppleEvent* theAppleEvent)
- {
- ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
- ODLinkSpecMethodDebug("ODLinkSpec","ReadFromAppleEvent");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fProcessLaunchDate = 0;
- _fProcessID.lowLongOfPSN = kNoProcess;
- _fProcessID.highLongOfPSN = 0;
- */
-
- OSErr result;
- DescType returnedType;
- Size actualSize;
- ODPart* part;
- ODByteArray partData;
- ProcessSerialNumber processID;
- ODULong processLaunchDate;
- ODULong dataSize;
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber, &returnedType,
- &processID, sizeof(processID), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger, &returnedType,
- &processLaunchDate, sizeof(processLaunchDate), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger, &returnedType,
- &part, sizeof(part), &actualSize);
- THROW_IF_ERROR(result);
-
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger, &returnedType,
- &dataSize, sizeof(ODULong), &actualSize);
- THROW_IF_ERROR(result);
-
- partData = CreateEmptyByteArrayStruct(dataSize);
-
- TRY
- if ( dataSize > 0 )
- {
- result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar, &returnedType,
- partData._buffer, dataSize, &actualSize);
- THROW_IF_ERROR(result);
- partData._length = dataSize;
- }
- somSelf->InitBaseLinkSpec(ev, part, &partData);
- CATCH_ALL
- DisposeByteArrayStruct(partData);
- RERAISE;
- ENDTRY
-
- DisposeByteArrayStruct(partData);
-
- _fProcessID = processID;
- _fProcessLaunchDate = processLaunchDate;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-